import { IPSAppView } from '@ibiz/dynamic-model-api';
import { Component, Host, h, Prop, ComponentInterface } from '@stencil/core';
import { controlName } from '../../../core';

/**
 * 视图模型展示
 *
 * @author chitanda
 * @date 2021-05-14 10:05:22
 * @export
 * @class IBzViewModel
 */
@Component({
  tag: 'ibz-view-model',
  styleUrl: 'ibz-view-model.scss',
})
export class IBzViewModel implements ComponentInterface {
  @Prop({})
  model: IPSAppView;

  renderViewContent(): any {
    return <div class='ibz-view-model-content'>{this.model?.name}</div>;
  }

  renderControls(): any {
    return <ibz-model-list getName={controlName} models={this.model.getPSControls()}></ibz-model-list>;
  }

  render() {
    if (!this.model) {
      return null;
    }
    return (
      <Host class='os-container ibz-view-model'>
        {this.renderViewContent()}
        {this.renderControls()}
      </Host>
    );
  }
}
